1 Setup

library(tidyverse)
library(here)
library(readr)
library(readxl)
library(data.table)

1.1 Loading in cleaned data

full_data <-
  read_csv(here("clean_data/birds_clean.csv"))

2 Data

2.1 Raw

"raw_data/seabirds.xls" %>%
    here() %>%
    read_excel() %>% 
    data.table()

2.2 Clean data

full_data %>% 
    data.table()

3 Questions

3.1 Finding the bird with the most individual sightings

highest_individual_sightings <- full_data %>% 
    count(species_abbreviation) %>% 
    top_n(1)
## Selecting by n
  highest_individual_sightings2 <- left_join(highest_individual_sightings, full_data, by = "species_abbreviation")
  
  highest_individual_sightings2 %>% 
    select(n, species_abbreviation, species_common_name_taxon_age_sex_plumage_phase, species_scientific_name_taxon_age_sex_plumage_phase) %>% 
    head(1)

3.2 Finding the bird with the highest total count?

highest_total_count <- full_data %>% 
 group_by(species_abbreviation) %>% 
    summarise(sum(count)) %>% 
    top_n(1)

  highest_total_count2 <- left_join(highest_total_count, full_data, by = "species_abbreviation")
  
  highest_total_count2 %>% 
    select("sum(count)", species_abbreviation, species_common_name_taxon_age_sex_plumage_phase, species_scientific_name_taxon_age_sex_plumage_phase) %>%
    head(1)

3.3 Finding bird with the highest total count above a latitude of -30?

highest_total_count_above_lat_30 <- full_data %>% 
    filter(lat > -30) %>% 
 group_by(species_abbreviation) %>% 
    summarise(sum(count)) %>% 
    top_n(1)


  highest_total_count_above_lat_30_again <- left_join(highest_total_count_above_lat_30, full_data, by = "species_abbreviation")
  
  highest_total_count_above_lat_30_again %>% 
    select("sum(count)", species_abbreviation, species_common_name_taxon_age_sex_plumage_phase, species_scientific_name_taxon_age_sex_plumage_phase) %>%
    head(1)

3.4 How many different types of birds were only ever seen in groups of 1?

full_data %>% 
    filter(count < 2)  %>% 
        select(species_common_name_taxon_age_sex_plumage_phase, species_scientific_name_taxon_age_sex_plumage_phase, species_abbreviation) %>%
        distinct() %>% 
    arrange(species_abbreviation) %>% 
    count()

3.5 How many penguins were seen? (N.B. there are many types of penguin)

full_data %>% 
    filter(str_detect( species_common_name_taxon_age_sex_plumage_phase, "penguin")) %>% 
    summarise(sum(count,na.rm = TRUE))